home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AMISL083.ARJ / VGABLANK.ASM < prev   
Assembly Source File  |  1992-05-02  |  6KB  |  231 lines

  1. ;-----------------------------------------------------------------------
  2. ; VGABLANK.ASM    Public Domain 1992 Ralf Brown
  3. ;        You may do with this software whatever you want, but
  4. ;        common courtesy dictates that you not remove my name
  5. ;        from it.
  6. ;
  7. ; Minimalist VGA screen blanker.
  8. ;
  9. ; Version 0.83
  10. ; LastEdit: 5/2/92
  11. ;-----------------------------------------------------------------------
  12.  
  13. __TINY__ equ 1                ; using Tiny model
  14.     INCLUDE AMIS.MAC
  15.  
  16. ;-----------------------------------------------------------------------
  17. ;
  18. VERSION_NUM equ 0053h    ; v0.83
  19. VERSION_STR equ "0.83"
  20.  
  21. ;-----------------------------------------------------------------------
  22. ; Declare our segments in the order we want them in the executable.
  23. ;
  24. _TEXT    SEGMENT PUBLIC BYTE 'CODE'
  25. _TEXT    ENDS
  26. TSRcode@
  27. TSRcodeEnd@
  28.  
  29. BIOS_SEG SEGMENT AT 40h
  30.     ORG 63h
  31. video_base dw ?
  32. BIOS_SEG ENDS
  33.  
  34. ;-----------------------------------------------------------------------
  35. ; Useful definitions
  36. ;
  37. VIDEO_DISABLE_BIT equ 20h
  38. VGA_REG       equ 3C4h
  39. TICKS_PER_MINUTE equ 0444h
  40.  
  41. ;-----------------------------------------------------------------------
  42. ; Put the resident code into its own segment so that all the offsets are
  43. ; proper for the new location after copying it into a UMB or down into
  44. ; the PSP.
  45. ;
  46. TSRcode@
  47. start_TSRcode label byte
  48.  
  49. ;-----------------------------------------------------------------------
  50. ; Declare the interrupt vectors hooked by the program, then set up the
  51. ; Alternate Multiplex Interrupt Spec handler
  52. ;
  53.     HOOKED_INTS 09h,1Ch
  54.     ALTMPX    'Ralf B','VGABLANK',VERSION_NUM
  55.  
  56. ;-----------------------------------------------------------------------
  57. ; Now the meat of the resident portion, the keyboard and timer tick
  58. ; interrupt handlers.
  59. ; We can save two bytes by specifying the hardware reset handler set up by
  60. ; the ALTMPX macro above
  61. ;
  62. time_count  dw 0            ; patched to actual timeout tick count
  63. video_state db 0
  64.  
  65. set_video_state:
  66.     push    dx
  67.     mov    dx,VGA_REG
  68.     mov    al,1
  69.     out    dx,al
  70.     inc    dx
  71.     in    al,dx
  72.     dec    dx
  73.     mov    video_state,ah
  74.     and    al,not VIDEO_DISABLE_BIT
  75.     or    ah,al
  76.     mov    al,1
  77.     out    dx,al
  78.     inc    dx
  79.     mov    al,ah
  80.     out    dx,al
  81.     pop    dx
  82.     ret
  83.  
  84. ISP_HEADER 1Ch,hw_reset_2Dh
  85.     sti                ; allow interrupts
  86.     dec    time_count        ; count down, and each time we hit
  87.     jnz    int1C_done        ; zero, force the video off
  88.     push    ax
  89.     mov    ah,VIDEO_DISABLE_BIT
  90.     call    set_video_state
  91.     pop    ax
  92. int1C_done:
  93.     JMP    ORIG_INT1Ch
  94.  
  95. ISP_HEADER 09h,hw_reset_2Dh
  96.     sti                ; allow interrupts
  97.         push    ax                      ; keystroke, so unblank display
  98.     mov    ah,0
  99.     cmp    ah,video_state        ; don't unblank unless currently blanked
  100.     je    int09_done        ; because of sparkles on some displays
  101.         call    set_video_state
  102. int09_done:
  103.     pop    ax
  104.     mov    time_count,0FFFFh    ; patched with actual timeout count
  105. MAX_TIME equ word ptr ($-2)
  106.     jmp    ORIG_INT09h
  107.  
  108. resident_code_size equ offset $
  109.  
  110. TSRcodeEnd@
  111.  
  112. ;-----------------------------------------------------------------------
  113.  
  114. _TEXT SEGMENT 'CODE'
  115.     ASSUME cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
  116.     ORG 100h
  117.  
  118. VGABLANK:
  119.     DISPLAY_STRING banner
  120.     CHECK_DOS_VER 2,00
  121.     mov    bx,1000h        ; set memory block to 64K
  122.     mov    ah,4Ah
  123.     int    21h
  124.     mov    si,81h            ; SI -> command line
  125.     cld                ; ensure proper direction for string ops
  126. cmdline_loop:
  127.     lodsb
  128.     cmp    al,' '            ; skip blanks and tabs on commandline
  129.     je    cmdline_loop
  130.     cmp    al,9
  131.     je    cmdline_loop
  132.     cmp    al,'1'            ; number of minutes specified?
  133.     jb    not_digit
  134.     cmp    al,'9'            ; if digit, go install TSR
  135.     jbe    installing
  136. not_digit:
  137.     and    al,0DFh            ; force to uppercase
  138.     cmp    al,'R'
  139.     je    removing
  140. usage:
  141.     mov    dx,offset _TEXT:usage_msg
  142.     jmp     exit_with_error
  143.  
  144. removing:
  145.     UNINSTALL <offset _TEXT:start_TSRcode>,RELBYTE,cant_uninstall
  146.     ;
  147.     ; force video back on in case we are called from a batch file while
  148.     ; the screen is blanked
  149.     ;
  150.     mov    ah,0
  151.     call    near ptr _TEXT:set_video_state
  152.     push    cs
  153.     pop    ds
  154.     ASSUME    DS:_TEXT
  155.     DISPLAY_STRING uninstalled_msg
  156. successful_exit:
  157.         mov     ax,4C00h
  158.     int    21h
  159.  
  160. installing:
  161.     sub    al,'0'
  162.     cbw
  163.     mov    bx,TICKS_PER_MINUTE
  164.     mul    bx
  165.     mov    timeout,ax        ; and remember for later
  166.     mov    ax,1A00h        ; get display combination code
  167.     int    10h
  168.     cmp    al,1Ah            ; supported? (i.e. VGA present?)
  169.     mov    dx,offset _TEXT:need_VGA_msg
  170.     jne    exit_with_error
  171.     ;
  172.     ; place any necessary pre-initialization here
  173.     ;
  174.     INSTALL_TSR <offset _TEXT:start_TSRcode>,RELBYTE,resident_code_size,BYTE,,BEST,TOPMEM,inst_patch,already_installed
  175.  
  176. cant_uninstall:
  177.     mov    dx,offset _TEXT:cant_remove_msg
  178. exit_with_error:
  179.     mov    ah,9
  180.     int    21h
  181.     mov    ax,4C01h
  182.     int    21h
  183.  
  184. already_installed:
  185.     cmp    cx,VERSION_NUM        ; same version installed?
  186.     jne    wrong_version
  187.     mov    al,0            ; request signature string
  188.     int    2Dh
  189.     mov    es,dx            ; ES -> resident code
  190.     ASSUME    ES:RESIDENT_CODE
  191.     mov    ax,timeout
  192.     mov    time_count,ax
  193.     mov    MAX_TIME,ax
  194.     DISPLAY_STRING timeout_changed_msg
  195.     jmp    successful_exit
  196.  
  197. wrong_version:
  198.     ASSUME    ES:NOTHING
  199.     mov    dx,offset _TEXT:already_inst_msg
  200.     jmp     exit_with_error
  201.  
  202. inst_patch:
  203.     push    es
  204.     mov    es,ax
  205.     ASSUME    ES:RESIDENT_CODE
  206.     mov    ax,timeout
  207.     mov    time_count,ax
  208.     mov    MAX_TIME,ax
  209.     pop    es
  210.     ASSUME    ES:NOTHING
  211.     DISPLAY_STRING installed_msg
  212.     ret
  213.  
  214. banner       db 'VGABLANK v',VERSION_STR,'  Public Domain 1992 Ralf Brown',13,10,'$'
  215. usage_msg  db 'Usage:',9,'VGABLANK n',9,"(n=1-9) install to blank after 'n' minutes",13,10
  216.        db 9,'VGABLANK R',9,'remove from memory',13,10
  217.        db "$"
  218. need_VGA_msg     db "This program requires a VGA.",13,10,"$"
  219. installed_msg    db "Installed.",13,10,"$"
  220. already_inst_msg db "Different version already installed.",13,10,"$"
  221. timeout_changed_msg db "Blanking time changed.",13,10,"$"
  222. cant_remove_msg  db "Can't remove from memory.",13,10,"$"
  223. uninstalled_msg  db "Removed.",13,10,"$"
  224.  
  225. timeout            dw ?
  226.  
  227. _TEXT ENDS
  228.  
  229.      end VGABLANK
  230.  
  231.